/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
 var isBalanced = function(root) {
    const getDeed = function(node){
        if(node==null) return 0
        let left = getDeed(node.left)
        if(left == -1) return -1
        let right = getDeed(node.right)
        if(right==-1) return -1
        if(Math.abs(left-right)>1) //当前节点高度
        {
            return -1
        }else{
            return 1+Math.max(left,right)
        }
    }
    return !(getDeed(root)===-1)
};